// https://nuxt.com/docs/api/configuration/nuxt-config
import dotenvFlow from 'dotenv-flow'
import { resolve, dirname } from 'node:path'
import { fileURLToPath } from 'url'
import VueI18nVitePlugin from '@intlify/unplugin-vue-i18n/vite'
// 必须在 defineNuxtConfig 之前加载环境变量
dotenvFlow.config({
  node_env: process.env.NODE_ENV || 'development'
})

export default defineNuxtConfig({
  build:{
    transpile:[/vue-i18n/]
  },
  modules: ['@nuxtjs/tailwindcss','@ant-design-vue/nuxt'],
  antd:{
    // Options
    extractStyle: true // 这个是关键参数
  },
  css: [
    '~/assets/css/preload.css',
    'ant-design-vue/dist/reset.css'
  ],
  // plugins: ['~/plugins/antd.ts'],
  vite: {
    css: {
      preprocessorOptions: {
        less: {
          javascriptEnabled: true, // 支持内联 JavaScript
          additionalData: '@import "@/assets/css/variables.less";',// 全局变量文件
          modifyVars: {
            'primary-color': '#775CE1',
            'link-color': '#775CE1',
            'border-radius-base': '8px',
          },
        }
      }
    },
    // 优化依赖预构建
    optimizeDeps: {
      include: ['ant-design-vue/es/locale/zh_CN', '@ant-design/icons-vue', 'dayjs/plugin/advancedFormat'],
    },
    resolve:{
      alias:{
        'vue-i18n':'vue-i18n/dist/vue-i18n.runtime.esm-bundler.js'
      }
    },
    plugins: [
      VueI18nVitePlugin({
        include: [
          resolve(dirname(fileURLToPath(import.meta.url)), './locales/*.json')
        ]
      })
    ]
  },
  nitro: {
    preset: 'node-server', // 确保使用正确的preset
    serveStatic: true,
    minify: true,
    compressPublicAssets: true,
    publicAssets: [{
      baseURL: '/',
      dir: 'public'
    }],
  },
  runtimeConfig: {
    public: {
      apiBase: process.env.NUXT_PUBLIC_API_BASE || '/api',
      env: process.env.NUXT_PUBLIC_ENV || 'development'
    },
    privateConfig: {
      apiSecret: process.env.API_SECRET
    }
  },
  app: {
    head: {
      link: [
        { rel: 'icon', type: 'image/svg+xml', href: '/Group.png' },
        // { rel: 'shortcut icon', type: 'image/x-icon', href: '/favicon.ico' }
      ]
    },
    baseURL: '/',
    buildAssetsDir: '/_nuxt/'
  }
})